05. console.log
console.log
console.log
Developer tools allow you to debug
console.log
is used to display content to the JavaScript console. Run the following code in the console:
console.log("hiya friend!");
Prints: "hiya friend!"
Congratulations! You performed the log
action on the debugging console
.
The message you’ve logged is "hiya friend!". hiya friend!
is a string (a sequence of characters).
Optional demo example
Let’s use console.log
to do something a little more interesting. Here’s a block of JavaScript code that loops through the numbers 0 through 9 and prints them out to the console:
for (var i = 0; i < 10; i++) {
console.log(i);
}
Prints:
0
1
2
3
4
5
6
7
8
9
This is called a loop.
Based on this loop's settings, any code written inside the curly brackets {...}
will be repeated 10 times. In this case, console.log
is printing out the value of i
each time the loop runs. Don't worry if you're not sure about what the syntax means at this point. You will learn more about how and when to use loops later in this course.
12_Img_gif Of What Happened (BETA)